package cn.wolfcode.interceptor;

import cn.wolfcode.domain.Employee;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LogInterceptor implements HandlerInterceptor {
    //前置拦截
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Employee employee = (Employee) session.getAttribute("EMPLOYEE_IN_SESSION");
        if(employee==null){//没有登录，不放行
            response.sendRedirect("/login.html");//回到登录页面
            return false;

        }
        //已经登录，放行
        return true;
    }
}
